import { edgeRequest, aphfRequest, apwsfRequest } from "@/utils/request";

export const listAPI = '/inference'

export const getDetail = async (id: string) => {
  return await edgeRequest(`/inference/${id}`, {
    method: 'GET',
  });
};

export async function addInference (params: object) {
  return await edgeRequest(`/inference`, {
    method: 'POST',
    data: params,
  })
}

export const getPublicImage = async () => {
  return await aphfRequest(`/images/publicImage`, {
    method: 'GET',
    params: {
      pageNum: 1,
      pageSize: 100
    }
  })
}

export const getMyImage = async () => {
  return await aphfRequest(`/images/image`, {
    method: 'GET',
    params: {
      pageNum: 1,
      pageSize: 100
    }
  })
}

export const getImageVersion = async (id: string|number) => {
  return await aphfRequest(`/images/${id}`, {
    method: 'GET',
  })
}

export const getImageVersions = async (id: string|number) => {
  return await aphfRequest(`/images/imageVersion`, {
    method: 'GET',
    params: {
      pageNum: 1,
      pageSize: 100,
      imageId: id,
    }
  })
}

export const getInference = async (modelId: string|number, versionId: string|number) => {
  return await apwsfRequest(`studioModelVersionInference/${modelId}/${versionId}`);
}

export const getNodes = async () => {
  return await edgeRequest(`node`, {
    method: 'GET',
    params: {
      pageNum: 1,
      pageSize: 10,
    }
  });
}

export const getServiceNodes = async (serviceId: string) => {
  return await edgeRequest(`/inference/serviceNode/${serviceId}`, {
    method: 'GET',
    params: {
      pageNum: 1,
      pageSize: 10,
    }
  });
}

export const deleteNode = async (nodeId: string) => {
  return await edgeRequest(`/inference/serviceNode/${nodeId}`, { method: 'DELETE' })
}

export const updateNode = async (serviceId: string, cmd: string) => {
  return await edgeRequest(`/inference/serviceNode`, {
    method: 'PATCH',
    data: {
      serviceNodeId: serviceId,
      cmd: cmd,
    }
  });
}

export const getPredict = async (serviceId: string) => {
  return await edgeRequest(`/inference/predict_info/${serviceId}`, { method: 'GET' });
}

export const imageAPI = '/images/image';

export const imageVersionAPI = '/images/imageVersion?imageId=';

export const nodeAPI = '/node';

export const groupAPI = '/node';

export const modelAPI = '/studioModels';

// export const modelVersionAPI = '/studioModelVersionsByModel?modelId=';
export const modelVersionAPI = '/studioModelVersionsByModel';

/**
 * 获取对应模型下的所有版本
 * @param modelId 模型id
 * @returns
 */
export const getModelVersions = async (modelId: number) => {
  return await apwsfRequest(`/studioModelVersionsByModel/${modelId}`, {
    method: 'GET',
  })
}

export const getModelVersion = async (modelId: number, versionId: number) => {
  return await apwsfRequest(`/studioModelVersion/${modelId}/${versionId}`, {
    method: 'GET',
  })
}
